<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script>
			/*function f1(a,b) {
				return a+b;
			}
			function f1(a,b,c) {
				return a*b*c;
			}
		console.log(f1(2,3));
		console.log(f1(2,3,4));*/
		/*function add(){
			var sum=0;
			for (var i=0;i<arguments.length;i++) {
				sum+=arguments[i]
			}
			return sum;
		}
		console.log(add(4,5));
		console.log(add(4,5,6));*/
		
		//定义一个函数：当传入2个参数时，实现两数之和，当传入3个参数时，实现3数相乘
		function add(){
			if (arguments.length==2) {
				var sum=0;
				for(var i=0;i<arguments.length;i++){
					sum+=arguments[i]
				}
				return sum;
			}else{
				var sum=1;
				for (var i=0;i<arguments.length;i++) {
					sum*=arguments[i]
				}
				return sum;
			}
		}
		console.log(add(4,5));
		console.log(add(4,5,6));
		</script>
	</body>
</html>
